#! /usr/bin/env python
# -*- coding: utf-8 -*-

from typing import Literal

from playwright.sync_api import Page

from common.base_page import BasePage
from common.logger import logger
from locators.majorHazardSourceSafety.olMonitorWarn.majorHazardSourceSafeCheck.loc_query import LocQuery
from locators.majorHazardSourceSafety.olMonitorWarn.majorHazardSourceSafeCheck.loc_safe_check import LocSafeCheck


class SafeCheck(BasePage):

    def __init__(self, page: Page):
        super().__init__(page)
        self.switch_menu('重大危险源安全管理')
        self.switch_menu('在线监测预警')
        self.switch_menu('重大危险源安全抽查')

    def query_total_list(self, danger_type, danger_level, danger_name, check_result, feedback_status):
        logger.info('开始重大危险源安全抽查查询测试')
        logger.info('选择重大危险源类型')
        self.select(LocQuery.loc_danger_type, danger_type)
        logger.info('选择重大危险源级别')
        self.select(LocQuery.loc_danger_level, danger_level)
        logger.info('输入重大危险源名称')
        self.fill(LocQuery.loc_danger_name, danger_name)
        logger.info('选择检查结果')
        self.select(LocQuery.loc_check_result, check_result)
        logger.info('选择反馈状态')
        self.select(LocQuery.loc_feedback_status, feedback_status)
        self.click(LocQuery.loc_query, exact=True)

    def reset(self):
        """
        测试重置
        :return:
        """
        self.click(LocQuery.loc_reset, exact=True)

    def export(self, export_type: Literal['all', 'part'], value_selected=None):
        logger.info('测试导出功能')
        if export_type == 'all':
            logger.info('直接点击导出按钮')
            res = self.export_and_download(LocSafeCheck.loc_export_button, file_type='excel')
        else:
            logger.info('勾选第一行')
            self.select_row_checkbox(value_selected)
            logger.info('导出数据')
            res = self.export_and_download(LocSafeCheck.loc_export_button, file_type='excel')
        return res

    def view(self):
        logger.info('开始安全检查记录查看测试')
        logger.info('点击查看按钮')
        self.click(LocSafeCheck.loc_view_button)

    def feedback(self, feedback_content):
        logger.info('开始安全检查反馈测试')
        logger.info('点击反馈按钮')
        self.click(LocSafeCheck.loc_feedback_button)
        logger.info('输入反馈内容')
        self.fill(LocSafeCheck.log_feedback_content, feedback_content)
        logger.info('提交')
        self.click(LocSafeCheck.loc_sumit_button)
